<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js布尔值之基础</title>
</head>
<body>
  <p>布尔值之基础</p>
  <ul>
    <li>布尔值可采用new Boolean()来定义, 使用valueOf来取值(不推荐)，而推荐使用简写：const isMarried = true</li>
  </ul>
  <script>
    // 正规写法(不推荐)
    // const isMarried = new Boolean(true)
    // console.log(typeof isMarried) // object
    // if (isMarried.valueOf()) {
    //   console.log('已婚人士，勿扰！')
    // }
    // 推荐写法
    const isMarried = true
    console.log(typeof isMarried)    // boolean
    if (isMarried) {
      console.log('已婚人士，勿扰！')
    }
    // 示例
    while (true) {
      const year = prompt('请问中华人民共和国是哪一年建立的？').trim()
      if (!year) continue
      console.log(year === '1949' ? '回答正确' : '回答错误')
      break
    }
  </script>
</body>
</html>